-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Detect redirects when emitting navigation spans #16324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
size-limit report 📦
|
❌ Unsupported file format
|
ccbd697
to
eb3c0bc
Compare
if (getClient() !== client) { | ||
return; | ||
} | ||
|
||
if (navigationOptions?.isRedirect) { | ||
DEBUG_BUILD && logger.warn('[Tracing] Detected redirect, navigation span will not be the root span.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEBUG_BUILD && logger.warn('[Tracing] Detected redirect, navigation span will not be the root span.'); | |
DEBUG_BUILD && logger.warn('[Tracing] Detected redirect, navigation span will not be the root span, but a child span.'); |
eb3c0bc
to
cb8e92e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me! There aren't many product areas in performance that specifically rely on navigations so I think this should be fine (and I think we'd consider surfacing redirects in those areas a bug anyways).
@@ -371,6 +396,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio | |||
startTrackingInteractions(); | |||
} | |||
|
|||
if (detectRedirects && optionalWindowDocument) { | |||
addEventListener('click', () => (lastClickTimestamp = timestampInSeconds()), { capture: true, passive: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there other events, such as key presses, that could indicate a user manually navigating?
Closes #15286
This PR adds a new option to
browserTracingIntegration
,detectRedirects
, which is enabled by default. If this is enabled, the integration will try to detect if a navigation is actually a redirect based on a simple heuristic, and in this case, will not end the ongoing pageload/navigation, but instead let it run and create anavigation.redirect
zero-duration span instead.An example trace for this would be: https://sentry-sdks.sentry.io/explore/discover/trace/95280de69dc844448d39de7458eab527/?dataset=transactions&eventId=8a1150fd1dc846e4ac8420ccf03ad0ee&field=title&field=project&field=user.display&field=timestamp&name=All%20Errors&project=4504956726345728&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=5m×tamp=1747646096&yAxis=count%28%29

Where the respective index route that triggered this has this code:
The used heuristic is:
this limit was chosen somewhat arbitrarily, open for other suggestions too.
While this logic will not be 100% bullet proof, it should be reliable enough and likely better than what we have today. Users can opt-out of this logic via
browserTracingIntegration({ detectRedirects: false })
, if needed.